package com.demo.widget.meis;


import com.demo.widget.ResourceTable;
import com.meis.widget.particle.FireflyView;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.service.WindowManager;
import ohos.app.Context;
import ohos.global.configuration.Configuration;
import ohos.global.resource.ResourceManager;

import java.util.Optional;

/**
 * Created by wenshi on 2018/7/5.
 * Description 浮动粒子界面
 */
public class MeiFireflyAbility extends Ability {
    private FireflyView firefly;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_mei_fire_fly_ability);
        getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);
        firefly = (FireflyView) findComponentById(ResourceTable.Id_firefly);
        getDirection(getContext());
    }

    private void getDirection(Context context) {
        Integer direction = Optional.ofNullable(context)
                .map(Context::getResourceManager)
                .map(ResourceManager::getConfiguration)
                .map(configuration -> configuration.direction)
                .orElse(Configuration.DIRECTION_UNDEFINED);
        //0-竖屏；1-横屏
        firefly.isLandscape(direction == 1);
    }
}
